<template>
  <MyDrawer title="面积" ref="myRef" @submit="submit" :disabled="false">
    <el-form label-width="120" :model="drawerProps.row" ref="formRef">
      <el-form-item label="排序值">
        <el-input-number :min="1" :max="10000" v-model="drawerProps.row.sort"></el-input-number>
      </el-form-item>
      <el-form-item label="类型">
        <el-radio-group v-model="drawerProps.row.areaType">
          <el-radio :label="0">以下</el-radio>
          <el-radio :label="1">之间</el-radio>
          <el-radio :label="2">以上</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="最小值">
        <el-input-number :min="1" :max="100000000" v-model="drawerProps.row.min"></el-input-number>
      </el-form-item>
      <el-form-item label="最大值">
        <el-input-number :min="1" :max="100000000" v-model="drawerProps.row.max"></el-input-number>
      </el-form-item>
    </el-form>
  </MyDrawer>
</template>

<script setup lang="ts">
import MyDrawer from "@/components/MyDrawer/index.vue";
import { ElMessage, FormInstance } from "element-plus";
import { ref } from "vue";

interface DrawerProps {
  row: any;
  api?: (params: any) => Promise<any>;
  getTable?: () => Promise<any>;
}

const initData: any = { sort: 1, areaType: 0, min: 0, max: 0 };

const drawerProps = ref<DrawerProps>(JSON.parse(JSON.stringify(initData)));

const myRef = ref<InstanceType<typeof MyDrawer> | null>();

const acceptParams = (params: any) => {
  drawerProps.value = params;
  myRef.value?.acceptParams();
};

const formRef = ref<FormInstance>();

const submit = () => {
  if (!formRef.value) return;
  formRef.value.validate(async valid => {
    if (!valid) return;
    await drawerProps.value.api!(drawerProps.value.row);
    ElMessage.success("成功");
    await drawerProps.value.getTable!();
    myRef.value?.close();
  });
};

defineExpose({ acceptParams });
</script>

<style></style>
